package com.ky.serialport.sensor;


import com.ky.serialport.bean.ComBean;
import com.ky.serialport.utils.MyFunc;

import static com.ky.serialport.utils.RandomUtils.myRandom;

/**
 * 温湿度传感器解析
 */

public class WenShiDuDataBean {

    public Long time = 0L;
    public float wdVel = 0F; //温度
    public float shdVel = 0F; //湿度
    public float dqyVel = 0f; //大气压
    public int power = 0; //电量
    public int signal = 0; //信号
    public int index = -1;
    public ComBean comBean;



    public WenShiDuDataBean() {
    }


    public WenShiDuDataBean(ComBean comBean ) {
        caculate(comBean.recData);
        time = comBean.recTime;
        this.comBean = comBean;
    }

    public WenShiDuDataBean(byte[] recData) {
        caculate(recData);
        time = System.currentTimeMillis();
    }

    public WenShiDuDataBean caculate(ComBean comBean){
        time = comBean.recTime;
        return caculate(comBean.recData);
    }

    public WenShiDuDataBean caculate(byte[] buffer) {
        power = MyFunc.getPower(buffer[26],buffer[27]);
        signal = MyFunc.getSignal(buffer[28]); //测试信号
        this.index = buffer[10];
        wdVel =  MyFunc.byte2float(buffer, 14);
        shdVel = MyFunc.byte2float(buffer, 18);
        dqyVel = MyFunc.fourByte2int(buffer, 22)/100f;
        return this;
    }

    public WenShiDuDataBean test() {
        time = System.currentTimeMillis();
        power = 300 + myRandom.nextInt(120);
        signal = 200;
        wdVel =  20 + myRandom.nextInt(5);
        shdVel = 70 + myRandom.nextInt(5);
        dqyVel = 1010 + myRandom.nextInt(5);;
        return this;
    }

}
